# -*- coding: utf-8 -*-
# @Time    : 2021/2/12 下午10:55
# @Author  : void bug
# @FileName: Serializers.py
# @Software: PyCharm
from rest_framework import serializers

from apps.Blog.models import *
from apps.Blog_User.Serializers import UserSerializers_all


class CategorySerializers:
    class CategorySerList(serializers.ModelSerializer):
        author = UserSerializers_all.Srlist(read_only=True)

        class Meta:
            model = Category
            fields = '__all__'

    class CreateSerializers(serializers.ModelSerializer):
        class Meta:
            model = Category
            fields = '__all__'


class TagSerializers:
    class TagListSerializers(serializers.ModelSerializer):
        author = UserSerializers_all.Srlist(read_only=True)

        class Meta:
            model = Tag
            fields = '__all__'

    class TagCreateSerializers(serializers.ModelSerializer):
        class Meta:
            model = Tag
            fields = '__all__'


class ArticleSerializers:
    class ArticleListSerializers(serializers.ModelSerializer):
        views = serializers.ReadOnlyField(read_only=True)
        author = UserSerializers_all.Srlist(read_only=True)
        category = CategorySerializers.CategorySerList(read_only=True)
        tags = TagSerializers.TagListSerializers(many=True, read_only=True)

        class Meta:
            model = Article
            fields = '__all__'

    class ArticleCreateSerializers(serializers.ModelSerializer):
        class Meta:
            model = Article
            fields = '__all__'

    class UpdateViewSerializers(serializers.ModelSerializer):
        class Meta:
            model = Article
            fields = '__all__'
            read_only_fields = ("author", "category", "tags", "title", "body", "status", "article_order")
